<?php

namespace app\common\model;


class Payments extends Base
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ddt_payments';
    // 主键ID
    protected $pk = 'payments_id';

    /**
     * @param array $where  // 查询的条件
     * @param string $item  // 查询的参数
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function getOne($where=[1], $item='*')
    {
        $rs = $this
            ->field($item)
            ->where($where)
            ->find();

        return $rs;
    }


    function get_list($where,$item){

        $where = null;

        if(!empty($cond['pid'])){
            $where[] = ['pid', '=',$cond['pid']];
        }

        if(!empty($cond['level'])){
            $where[] = ['level', '=',$cond['level']];
        }

        $rs = $this
            ->field($item)
            ->where($where)
            ->select();
        return $rs;
    }

//    订单插入操作
    function insertpayments($insertdata,$ptype){
        $orderno = "wx".date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
        $data = [
            'order_nos' => $orderno,
            'user_id' => $insertdata['user']['user_id'],
            'user_name' => $insertdata['user']['nick_name'],
            'amount' => $insertdata['data']['pay_amount'],
            'payments_type' => $ptype,
        ];
        $rs = $this->save($data);
        if ($rs === false) {
            return false;
        }
        $orderid = $this->payments_id;
        return $orderid;
    }
}